<!DOCTYPE html>
<html>
	{include file="public/header" /}
	<style type="text/css">
		.diyinput {
			height: 38px;
			line-height: 1.3;
			line-height: 38px;
			border-width: 1px;
			border-style: solid;
			background-color: #fff;
			border-radius: 2px;
			border-color: #f1eeee;
		}
	</style>
	<body>
		<div class="layui-fluid">
			<div class="layui-card">
				<div class="layui-form layui-card-header layuiadmin-card-header-auto">
					<div class="layui-form-item">
						{include file="public/sorch" /} 
						<!--{include file="public/loanstatus" /}-->
						<div class="layui-inline">
							<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
						</div>
					</div>
				</div>
				<div class="layui-card-body">
					<table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
					<script type="text/html" id="imgTpl">
						<img style="display: inline-block; width: 50%; height: 100%;" src={ { d.avatar }}>
					</script>
					
				  {eq name="RoleID" value="51"}
				   <script type="text/html" id="table-useradmin-webuser">
				   	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="detail"><i class="layui-icon "></i>详情</a>
					<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="beizhu"><i class="layui-icon"></i>备注</a>
					</script>
					{else/}
					<script type="text/html" id="test-table-toolbar-toolbarDemo">
						<div class="layui-btn-container">
							<button class="layui-btn layui-btn-sm" lay-event="getCheckData">分配内催专员</button>
						</div>
					</script>
					<script type="text/html" id="table-useradmin-webuser">
						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="detail"><i class="layui-icon "></i>详情</a>
						<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="huankuan"><i class="layui-icon "></i>还款</a>
						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="zhanqi"><i class="layui-icon "></i>展期</a>
						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="beizhu"><i class="layui-icon"></i>备注</a>
						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="daikou"><i class="layui-icon "></i>代扣</a>
					</script>
					{/eq}
					
				</div>
			</div>
		</div>
		{include file="public/footer" /}
		<script>
			layui.use(['index', 'table', 'laydate'], function() {
				var $ = layui.$,
					form = layui.form,
					table = layui.table,
					laydate = layui.laydate;

				laydate.render({
					elem: '#time1' //指定元素
				});
				laydate.render({
					elem: '#time2' //指定元素
				});
				table.render({
					elem: '#LAY-user-manage',
					even: true, //开启隔行背景
					url: "{:url('admin/orderhuankuan/get_list')}?songsong=dangri",
					toolbar: '#test-table-toolbar-toolbarDemo',
					title: '用户数据表',
					height: 'full-300',//最大高度
					cols: [
						[{
								type: 'checkbox',
								fixed: 'left'
							},
							{
								type: 'numbers',
								title: '排序',
								width: 40,
								fixed: 'left',
								unresize: true,
							},
							{
								field: 'TrueName',
								title: '用户名',
								width: 80,
							},
							{
								field: 'Mobile',
								title: '手机号',
								width: 120,

							},

							{
								field: 'DaichaoName',
								title: '渠道',
								width: 80,

							},
							{
								type: 'hidden',
								field: 'ID',
								title: 'ID',
								width: 120
							},
							
							{
								field: 'beizhu',
							    title: "<span lay-tips='这里仅显示最新一条备注，查看全部备注请去详情里面'>备注？</span>",
								width: 100,
							},
							{
								field: 'LoanStatus',
								title: '状态',
								width: 80,
							},
							
							{
								field: 'ApplyMoney',
								title: '订单金额',
								width: 100,
							},
							{
								field: 'ApplyDay',
								title: '期限',
								width: 60,
							},
							{
								field: 'AdoptMoney',
								title: '到账金额',
								width: 100,
							},
							{
								field: 'fakuan',
								title: '应还罚息',
								width: 100,
							},
							{
								field: 'ApplyMoney',
								title: '到期应还',
								width: 100,
							},

							{
								field: 'user_type',
								title: '客户类型',
								width: 100,
							},
							{
								field: 'OrderSn',
								title: '订单编号',
								width: 180,
							},
							{
								field: 'OpenTime',
								title: '放款时间',
								width: 160,
							},
							{
								field: 'YyFkTime',
								title: '预约还款时间',
								width: 160,
							},
							{
								field: 'SjFkTime',
								title: '实际还款时间',
								width: 160,
							},
							{
								field: 'bufenhuankuan',
								title: '部分还款',
								width: 100,
							},

							{
								field: 'bufenhuankuan_num',
								title: '次数',
								width: 80,
							},

							{
								field: 'yuqi_status',
								title: '是否逾期',
								width: 100,
							},
							{
								field: 'datas',
								title: '逾期天数',
								width: 100,
							},
							{
								field: 'xjnums_status',
								title: '是否展期',
								width: 100,
							},

							{
								field: 'xjnums',
								title: '展期次数',
								width: 100,
							},
							{
								field: 'Jktime',
								title: '(总)借款次数',
								width: 120
							},
							{
								field: 'waicuishourenID',
								title: '内崔专员',
								width: 140,
							},
							{
										field: 'OrderSn',
										title: '订单编号',
										width: 180,
									},
							{
								fixed: 'right',
								title: '操作',
								toolbar: '#table-useradmin-webuser',
								align: 'center',
								width: 280
							}
						]

					],
					page: true,
					done: function() {
						$("[data-field='ID']").css('display', 'none');
					}
				});

				//监听工具条
				table.on('tool(LAY-user-manage)', function(obj) {
					var data = obj.data;
					if(obj.event === 'detail') {
						layer.open({
							type: 2,
							title: '用户详情',
							content: 'detail.html?ID=' + data.ID,
							area: ['90%', '90%'],
							btn: ['确定', '取消'],

						});

					} else if(obj.event === 'zhanqi') {
						layer.open({
							type: 2,
							title: '展期用户',
							content: 'zhanqi.html?ID=' + data.ID,
							area: ['50%', '80%'],
							btn: ['确定', '取消'],
							yes: function(index, layero) {
								var iframeWindow = window['layui-layer-iframe' + index],
									submitID = 'LAY-user-back-submit',
									submit = layero.find('iframe').contents().find('#' + submitID);
								//监听提交
								iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
									var field = data.field; //获取提交的字段
									//								
									//提交 Ajax 成功后，静态更新表格中的数据
									$.ajax({
										'type': 'post',
										'url': "{:url('admin/orderhuankuan/zhanqi_caozuo')}",
										'data': field,
										dataType: 'json',
										success: function(res) {
											if(res.code == '0') {
												layer.msg(res.msg, {
													icon: 1
												});
											} else {
												layer.msg(res.msg, {
													icon: 5
												});
											}
											table.reload('LAY-user-manage');
											layer.close(index); //关闭弹层
										}
									});

								});

								submit.trigger('click');
							}
						});
					} else if(obj.event === 'huankuan') {
						layer.open({
							type: 2,
							title: '线下还款',
							content: 'huankuan.html?ID=' + data.ID,
							area: ['50%', '80%'],
							btn: ['确定', '取消'],
							yes: function(index, layero) {
								var iframeWindow = window['layui-layer-iframe' + index],
									submitID = 'LAY-user-back-submit',
									submit = layero.find('iframe').contents().find('#' + submitID);
								//监听提交
								iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
									var field = data.field; //获取提交的字段
									//								
									//提交 Ajax 成功后，静态更新表格中的数据
									$.ajax({
										'type': 'post',
										'url': "{:url('admin/orderhuankuan/huankuan_caozuo')}",
										'data': field,
										dataType: 'json',
										success: function(res) {
											if(res.code == '0') {
												layer.msg(res.msg, {
													icon: 1
												});
											} else {
												layer.msg(res.msg, {
													icon: 5
												});
											}
											table.reload('LAY-user-manage');
											layer.close(index); //关闭弹层
										}
									});

								});

								submit.trigger('click');
							}
						});
					}else if(obj.event === 'beizhu') {
						
						layer.open({
							type: 2,
							title: '备注',
							content: 'beizhu.html?ID=' + data.ID,
							area: ['70%', '70%'],
							btn: ['确定', '取消'],
							yes: function(index, layero) {
								var iframeWindow = window['layui-layer-iframe' + index],
									submitID = 'LAY-user-role-submit',
									submit = layero.find('iframe').contents().find('#' + submitID);
								//监听提交
								iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
									var field = data.field; //获取提交的字段
									//								
									//提交 Ajax 成功后，静态更新表格中的数据
									$.ajax({
										'type': 'post',
										'url': "{:url('admin/orderyuqi/beizhu_caozuo')}",
										'data': field,
										dataType: 'json',
										beforeSend: function(XMLHttpRequest) {
											//注意，layer.msg默认3秒自动关闭，如果数据加载耗时比较长，需要设置time
											loadingFlag = layer.msg('正在读取数据，请稍候……', {
												icon: 16,
												shade: 0.01,
												shadeClose: false,
												time: 60000
											});
										},
										success: function(res) {
											if(res.code == '0') {
												layer.msg(res.msg, {
													icon: 1
												});
											} else {
												layer.msg(res.msg, {
													icon: 5
												});
											}
											table.reload('LAY-user-manage');
											layer.close(index); //关闭弹层
										}
									});

								});
								submit.trigger('click');
							}

						});

					
					}else if(obj.event === 'daikou') {
						layer.open({
							type: 2,
							title: '后台代扣 全款 展期',
							content: 'daikou.html?ID=' + data.ID,
							area: ['50%', '80%'],
							btn: ['确定', '取消'],
							yes: function(index, layero) {
								var iframeWindow = window['layui-layer-iframe' + index],
									submitID = 'LAY-user-back-submit',
									submit = layero.find('iframe').contents().find('#' + submitID);
								//监听提交
								iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
									var field = data.field; //获取提交的字段
									//								
									//提交 Ajax 成功后，静态更新表格中的数据
									$.ajax({
										'type': 'post',
										'url': "{:url('admin/orderhuankuan/daokou_caozuo')}",
										'data': field,
										dataType: 'json',
										beforeSend: function (XMLHttpRequest) {
										        //注意，layer.msg默认3秒自动关闭，如果数据加载耗时比较长，需要设置time
										  loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
										},
										success: function(res) {
											if(res.code == '0') {
												layer.msg(res.msg, {
													icon: 1
												});
											} else {
												layer.msg(res.msg, {
													icon: 5
												});
											}
											table.reload('LAY-user-manage');
											layer.close(index); //关闭弹层
										}
									});

								});

								submit.trigger('click');
							}
						});
					} 
				});
				//监听搜索
				form.on('submit(LAY-user-front-search)', function(data) {
					var field = data.field;

					//执行重载
					table.reload('LAY-user-manage', {
						where: field
					});
				});

			
				//				设置催收人员
				table.on('toolbar(LAY-user-manage)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);
					switch(obj.event) {
						case 'getCheckData':
							var data = checkStatus.data;
							var idarr = data.map((item, index) => {
								return item.ID
							})
							var idarr = JSON.stringify(idarr);

							layer.open({
								type: 2,
								title: '分配催收专员',
								content: 'couishou_people_add.html',
								area: ['520px', '520px'],
								btn: ['确定', '取消'],
								yes: function(index, layero) {
									var iframeWindow = window['layui-layer-iframe' + index],
										submitID = 'LAY-user-back-submit',
										submit = layero.find('iframe').contents().find('#' + submitID);
									//监听提交
									iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
										var field = data.field; //获取提交的字段
										//提交 Ajax 成功后，静态更新表格中的数据
										$.ajax({
											'type': 'post',
											'url': "{:url('admin/orderyuqi/cuishou_people')}",
											'data': {
												'idarr': idarr,
												'cuishouren': field['cuishou']
											},
											dataType: 'json',
											success: function(res) {
												if(res.code == '0') {
													layer.msg(res.msg, {
														icon: 1
													});
												} else {
													layer.msg(res.msg, {
														icon: 5
													});
												}
												table.reload('LAY-user-manage');
												layer.close(index); //关闭弹层
											}
										});
									});

									submit.trigger('click');
								}
							});
							break;
						case 'getCheckLength':
							var data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
							break;
						case 'isAll':
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
							break;
					};
				});

				$('.layui-btn.layuiadmin-btn-useradmin').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
				var laydate = layui.laydate;

				//日期范围
				laydate.render({
					elem: '#test6',
					range: true
				});
			});
		</script>
	</body>

</html>